package Q1;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int t = scanner.nextInt();
        while (t > 0) {
            t--;
            int n = scanner.nextInt();
            int k = scanner.nextInt();
            String str = scanner.next();

            int winCount = 0; //胜利的场数
            int ret = 0;
            for (int i = 0; i < n; i++) {
                if (str.charAt(i) == 'L') {
                    //失败
                    winCount = 0;
                    ret--;
                } else {
                    //胜利
                    winCount++;
                    if (winCount >= 3) {
                        ret += k;
                    } else {
                        ret++;
                    }
                }
            }

            System.out.println(ret);
        }
    }
}
